package api

import (
	"gateway/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func QiNiuYun(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":  400,
			"msg":   "文件上传失败",
			"error": err.Error(),
		})
		return
	}
	open, _ := file.Open()
	url, err := pkg.QiNiuYun(open, file.Filename)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":  400,
			"msg":   "图片上传失败",
			"error": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "图片上传成功",
		"data": url,
	})
}
